<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8" />
		<title>Vue中多个元素或组件的过渡</title>
		<script type="text/javascript" src="js/vue.js" ></script>
		<style>
			.v-enter, .v-leave-to {
				opacity: 0;
			}
			.v-enter-active, .v-leave-active {
				transition: opacity 1s;
			}
		</style>

	</head>
	<body>
		<div id="root">
			<transition mode="out-in">
				<!--多个元素的过渡-->
				<!--<div v-if="show" key="one">child-one</div>
				<div v-else key="two">child-two</div>-->
				<!--多个组件-->
				<!--<child-one v-if="show"></child-one>
				<child-two v-else></child-two>-->
				<!--动态组件-->
				<component :is="type"></component>
			</transition>
        	<button @click="handleBtnClick">切换</button>
        </div>
		
		<script>
			
			Vue.component("child-one", {
				template: "<div>child-one</div>"
			})
			
			Vue.component("child-two", {
				template: "<div>child-two</div>"
			})
			
			var vm = new Vue({
				el: '#root',
				data: {
					type: "child-one"
				},
				methods: {
					handleBtnClick: function() {
						this.type = (this.type === "child-one") ? "child-two" : "child-one"
					}
					
				}
			})
			
		</script>
	</body>
</html>
